package edcom.server;

import edcom.client.Student;

public class LoginController {
	Student currentStudent;
	StudentManager mgr;
	
	public LoginController(){
		this.currentStudent = new Student();
		this.mgr = new StudentManager();
	}
	
	public void setUsername(String src) throws MalformedStringException
	{
		if((src == null) || (src == "")) 
			throw new MalformedStringException("You entered nothing.");
		currentStudent.setUserName(src);
	}
	
	public void setPassword(String src) throws MalformedStringException
	{
		if((src == null) || (src == "")) 
			throw new MalformedStringException("You entered nothing.");
		currentStudent.setPassword(src);
	}
	
	public Student login() throws IncompleteDataException, SQLSelectException
	{
		if((currentStudent.getUserName() == "") || 
				(currentStudent.getPassword() == ""))
			throw new IncompleteDataException("Missing data field(s).");
		
		// automatically throws SQLSelectException
		try {
			currentStudent = mgr.getStudentUsingLoginKeys(
					currentStudent.getUserName(), currentStudent.getPassword());
		} catch (Exception e) {
			throw new SQLSelectException(e.getMessage());
		} 
		
		return currentStudent;// */
	}
}
